/**
 * Created by sony on 2017/4/26.
 */
import java.io.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public class week1004 {
        public static void main(String args[]) throws Exception{
            KeyPairGenerator kpg=KeyPairGenerator.getInstance("RSA");
            kpg.initialize(1024);
            KeyPair kp=kpg.genKeyPair();
            PublicKey pbkey=kp.getPublic();
            PrivateKey prkey=kp.getPrivate();
            //  保存公钥
            FileOutputStream  f1=new FileOutputStream("Skey_RSA_pub.dat");
            ObjectOutputStream b1=new  ObjectOutputStream(f1);
            b1.writeObject(pbkey);
            //  保存私钥
            FileOutputStream  f2=new FileOutputStream("Skey_RSA_priv.dat");
            ObjectOutputStream b2=new  ObjectOutputStream(f2);
            b2.writeObject(prkey);
        }
    }
